from fastapi import APIRouter, Body
from pydantic import BaseModel

from models.task import task_model
from items.http_api_response import HTTPApiResponse
from api.routers.task.examples import examples

router = APIRouter(prefix='/task', tags=["任务"])


class TaskCreateItem(BaseModel):
    platform: str
    browser_id: str
    exe_models: dict[str, list[dict]]  # 需要执行的模块
    module_reference: str  # 模块映射路径


@router.post("/create")
async def create(item: TaskCreateItem = Body(..., examples=examples)):
    await task_model.create(
        platform=item.platform,
        browser_id=item.browser_id,
        exe_models=item.exe_models,
        module_reference=item.module_reference
    )
    return HTTPApiResponse.success(data=None)
